using System;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;

namespace OracleInternal.TTC
{
	internal class TTCReExecuteSql : TTCFunction
	{
		internal const int EXE_COMMIT_ON_SUCCESS = 1;

		internal TTCReExecuteSql(MarshallingEngine mEngine)
			: base(mEngine, 4, 0)
		{
		}

		internal void WriteMessage(short ttcCallCode, int cursorId, int exerof, int execFlags, long numIterations, bool bArrayBinding, ref TTCExecuteSql.MarshalBindParameterValueHelper marshalBindParamsHelper)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCReExecuteSql, OracleTraceFuncName.WriteMessage);
			}
			try
			{
				m_functionCode = ttcCallCode;
				WriteFunctionHeader();
				m_marshallingEngine.MarshalSWORD(cursorId);
				m_marshallingEngine.MarshalSWORD((int)numIterations);
				m_marshallingEngine.MarshalSWORD(exerof);
				m_marshallingEngine.MarshalSWORD(execFlags);
				object[] paramValueArray = marshalBindParamsHelper.m_paramValueArray;
				if (paramValueArray != null && paramValueArray.Length != 0)
				{
					if (bArrayBinding)
					{
						TTCExecuteSql.MarshalValuesForArrayBind(m_marshallingEngine, (int)numIterations, 0, ref marshalBindParamsHelper);
					}
					else
					{
						TTCExecuteSql.MarshalBindValues(m_marshallingEngine, ref marshalBindParamsHelper);
					}
				}
				m_marshallingEngine.m_oraBufWriter.FlushData();
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCReExecuteSql, OracleTraceFuncName.WriteMessage, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCReExecuteSql, OracleTraceFuncName.WriteMessage);
				}
			}
		}
	}
}
